package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
public class CartController {
    @Autowired
    private CartService cartService;
    //新增购物车
    @PostMapping("/cart/add")
    public ResultInfo save(@RequestBody Cart cartParam){
        //调用service
        Cart cart=cartService.save(cartParam);
        return ResultInfo.success(cart);
    }
    //查询购物车
    @GetMapping("/cart/list")
    public ResultInfo findList(){
        List<Cart> cartList=cartService.findList();
        return ResultInfo.success(cartList);
    }
    //更新购物车
    @PostMapping("/cart/sub")
    public ResultInfo sub(@RequestBody Cart cartParam){
        //调用service
        Cart cart=cartService.update(cartParam);
        return ResultInfo.success(cart);
    }
   //删除购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo delete(){
        //调用service
        cartService.delete();
        return ResultInfo.success(null);
    }
}
